﻿// Write a program that downloads a file from Internet (e.g. http://www.devbg.org/img/Logo-BASD.jpg) 
// and stores it the current directory. 
// Find in Google how to download files in C#. 
// Be sure to catch all exceptions and to free any used resources in the finally block.

using System;
using System.Net;

public class Program
{
    private static void Main()
    {
        using (WebClient webClient = new WebClient())
        {
            Console.Write("Enter URL to download image: ");
            string url = Console.ReadLine();
            Console.Write("Enter path to save the file: ");
            string path = Console.ReadLine();
            if (path == null || path.Equals(string.Empty))
            {
                path = Environment.CurrentDirectory;
            }

            try
            {
                webClient.DownloadFile(url, path);
            }
            catch (Exception e)
            {
                string message;
                if (e.InnerException != null)
                {
                    message = e.InnerException.Message;
                }
                else
                {
                    message = e.Message;
                }

                Console.WriteLine("Error occur: {0}", message);
            }
        }
    }
}